//
//  YKTabBar.m
//  百思不得姐
//
//  Created by Eric.Wu on 16/2/24.
//  Copyright © 2016年 Eric.Wu. All rights reserved.
//

#import "YKTabBar.h"
@interface YKTabBar ()
@property (nonatomic,weak) UIButton *publishButton;

@end
@implementation YKTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        UIButton *publishButton = [[UIButton alloc] init];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [self addSubview:publishButton];
       
        self.publishButton = publishButton;
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.publishButton.center = CGPointMake(self.width*0.5, self.height*0.5);
    self.publishButton.size = self.publishButton.currentBackgroundImage.size;
    // 原来的4个
    CGFloat width = self.width / 5;
    int index = 0;
    for (UIControl *control in self.subviews) {
        if (![control isKindOfClass:[UIControl class]] || [control isKindOfClass:[UIButton class]]) continue;
        control.width = width;
        control.x = index > 1 ? width * (index + 1) : width * index;
        index++;
    }

}
@end
